package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.lkt.common.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BBusinessDetailsEntity;
import io.lkt.modules.sys.service.BBusinessDetailsService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 商学院课程详情信息表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2020-10-23 18:17:52
 */
@RestController
@RequestMapping("/sys/bbusinessdetails")
public class BBusinessDetailsController {
    @Autowired
    private BBusinessDetailsService bBusinessDetailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:bbusinessdetails:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bBusinessDetailsService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:bbusinessdetails:info")
    public R info(@PathVariable("id") Integer id){
        BBusinessDetailsEntity bBusinessDetails = bBusinessDetailsService.getById(id);
        return R.ok().put("bBusinessDetails", bBusinessDetails);
    }

    @RequestMapping("/infoByBusinessId/{businessId}")
//    @RequiresPermissions("sys:bbusinessdetails:info")
    public R infoByBusinessId(@PathVariable("businessId") Integer businessId){
        BBusinessDetailsEntity bBusinessDetails = new BBusinessDetailsEntity();

        bBusinessDetails.setBusinessId(businessId);
        //通过课程id查询关联的课程小节实体
        List<BBusinessDetailsEntity> bBusinessDetailsEntityList = bBusinessDetailsService.queryAll(bBusinessDetails);

        return R.ok().put("bBusinessDetails", bBusinessDetailsEntityList);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:bbusinessdetails:save")
    public R save(@RequestBody BBusinessDetailsEntity bBusinessDetails){

        bBusinessDetails.setCreateTime(new Date());
        bBusinessDetails.setUpdateTime(new Date());
        bBusinessDetailsService.save(bBusinessDetails);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:bbusinessdetails:update")
    public R update(@RequestBody BBusinessDetailsEntity bBusinessDetails){
        ValidatorUtils.validateEntity(bBusinessDetails);

        bBusinessDetails.setUpdateTime(new Date());
        bBusinessDetailsService.updateById(bBusinessDetails);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:bbusinessdetails:delete")
    public R delete(@RequestBody Integer[] ids){
        bBusinessDetailsService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
